/**
 * Copyright ©2016-2020 northkingbpo Corporation, All Rights Reserved
 * http://www.northkingbpo.net/
 */
package profile.hujia.springcloudhystrix.remote;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.net.URL;

/**
 * class info
 *
 * @author hujia
 * @date 2018/12/12 09:33
 */
@Service
@Slf4j
public class CallRemoteService {

    @HystrixCommand(fallbackMethod = "getRemoteFallback")
    public String getRemoteService() throws Exception {
        URL url = new URL("http://localhost:50010/base/timeout");
        byte[] result = new byte[1024];
        url.openStream().read(result);
        return new String(result);
    }

    public String getRemoteFallback(Throwable e) {
        log.error("remote call fallback.", e);
        return "getRemoteFallback failed.";
    }

}
